// const path = require('path');
// const webpack = require('webpack');
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");

// const resolveApp = require('./paths')

module.exports = {
  // mode: 'production',
  mode: "development",
  // bail: false,
  devtool: "cheap-module-source-map",
  devServer: {
    hot: true,
    // hotOnly: true,
    // host: '0.0.0.0',
    host: "localhost",
    port: "8080",
    open: true,
    proxy: {
      "/api": {
        target: "http://localhost:3030",
        pathRewrite: {
          "^/api": ""
        },
        secure: false,
        changeOrigin: true,
      },
      "/test2": {
        target: "http://localhost:3080",
        secure: false,
        pathRewrite: {
          "^/test2": ""
        },
        changeOrigin: true,
      },
    },
    historyApiFallback: true,
    client: {
      logging: "none",
      overlay: {
        errors: false,
        warnings: false,
      },
      progress: false,
    },
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
            },
          },
          {
            loader: "postcss-loader",
            options: {
              // postcssOptions: {
              //   plugins: [
              //     'postcss-preset-env',  //简写
              //     require('postcss-preset-env') //包含autoprefixer插件
              //   ]
              // }
              // execute: true,
            },
          },
        ],
        sideEffects: true,
      },
      {
        test: /\.less$/i,
        use: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
            },
          },
          {
            loader: "postcss-loader",
            options: {
              // postcssOptions: {
              //   plugins: [
              //     'postcss-preset-env',  //简写
              //     require('postcss-preset-env') //包含autoprefixer插件
              //   ]
              // }
              // execute: true,
            },
          },
          {
            loader: "less-loader",
            options: {
              lessOptions: {
                javascriptEnabled: true,
              },
            },
          },
        ],
        sideEffects: true,
      },
    ],
  },
  plugins: [
    new ReactRefreshWebpackPlugin(), //只在开发环境下使用
  ],
};
